export function getGuid() {
    const target = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
    return target.replace(/[x]/g, (c) => {
      const r = Math.random() * 16 | 0,
        v = c === 'x' ? r : (r & 0x3 | 0x8);
      return v.toString(16);
    });
}

export function getPageConfig() {
    return {
        mark: getGuid(),
        duration: 5000,
        background: {
            data: {},
            style: {

            },
        },
        components: [],
        // [{
        //     mark: getGuid(),
        //     name: 'x-text',
        //     curStatus: '',
        //     status: [{
        //         id: getGuid(),
        //         timer: 0,
        //         data: {},
        //         style: {
        //             width: 480,
        //             height: 320,
        //         },
        //     }],
        //     tweens: [{
        //         startId: 0,
        //         endId: 0,
        //         func: 'none',
        //     }],
        //     animations: [{
        //         id: '',
        //         start: 0,
        //         duration: 1000,
        //         name: '',
        //     }]
        // }],
        // 入场
        transition: {
            name: 'none',
            duration: 10,
        },
    };
}

export function formatTimeline(duration) {
    const time = Math.round(duration / 1000);
    const min = Math.round(time / 60);
    const ms = time % 60;
    const minText = min > 9 ? min : `0${min}`;
    const msText = ms > 9 ? ms : `0${ms}`;
    return `${minText}:${msText}`;
}

export function colorRgb(val){
    let color = val.toLowerCase();
    let pattern = /^#([0-9|a-f]{3}|[0-9|a-f]{6}|[0-9|a-f]{4}|[0-9|a-f]{8})$/;
    if(color && pattern.test(color)) {
        let isOp = color.length === 5 || color.length === 9;
        let op = 1;
        if (color.length === 5) {
            op = parseInt(`0x${color[4]}${color[4]}`) / 255;
            color = color.substr(0, color.length - 1);
        } else if (color.length === 9) {
            op = parseInt(`0x${color[7]}${color[8]}`) / 255;
            color = color.substr(0, color.length - 2);
        }
        console.log('calc===>', color)
        if(color.length == 4) {
            // 将三位转换为六位
              color = '#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3];
        }
        //处理六位的颜色值
        var colorNew = [];
        for (var i=1; i<7; i+=2) {
            colorNew.push(parseInt("0x"+color.slice(i, i+2)));  
        }
        return `RGB${isOp ? 'A' : ''}(` + colorNew.join(",") + `${isOp ? `,${op}` : ''})`;
    }
    return color;
};